<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class TestKml extends CI_Controller {

	public function index()
	{
		$this->load->view('pruebas/testkml_view');
	}
	public function createXML()
	{
		$data=$this->input->post('data', TRUE);
	
		
		if(!$file=fopen("./places/kml/fichero33.kml", "w"))//'x'
		{
			echo "el archivo ya existe, error";
			return;
		}
		
		$fileData=
			'
				<?xml version="1.0" encoding="UTF-8"?>
				<kml xmlns="http://www.opengis.net/kml/2.2">
				  <Placemark>
				    <name>The Pentagon</name>
				    <Polygon>
				      <outerBoundaryIs>
				        <LinearRing>
				          <coordinates>
							'.$data=$this->input->post('data', TRUE).'
				          </coordinates>
				        </LinearRing>
				      </outerBoundaryIs>
				    </Polygon>
				  </Placemark>
				</kml>
			';
		fwrite($file,$fileData);
		echo $fileData;
	}
	public function takeKML()
	{	
		$fileData=
		'
				<?xml version="1.0" encoding="UTF-8"?>
				<kml xmlns="http://www.opengis.net/kml/2.2">
				  <Placemark>
				    <name>aaa</name>
				    <Polygon>
				      <outerBoundaryIs>
				        <LinearRing>
				          <coordinates>
							21.445399555874246,-87.95654296875,0 21.250982076868247,-87.94830322265625,0 21.261220997023248,-87.5775146484375,0 21.453068633086783,-87.61871337890625,0 
				          </coordinates>
				        </LinearRing>
				      </outerBoundaryIs>
				    </Polygon>
				  </Placemark>
				</kml>
			';
		
		echo $fileData;
	}
}
?>